package com.wongoing.util;

import java.util.List;

import com.wongoing.base.PageResult;
/**
 * <p>Title: PageUtil类</p>
 * <p>Description:封装分页类</p>
 * <p>Company: mesnac</p>
 * @author wuzq
 * @date 2017-5-9下午1:25:10
 * @retrun
 */
public class PageUtil {
	
	/**
	 * <p>Title:pageSet</p>
	 * <p>Description:获取分页类PageResult<T>的方法</p>
	 * <p>Company: mesnac</p>
	 * @param clazz log所需类参数
	 * @param pageSize 总页数
	 * @param pageCurrent 当前页数
	 * @param orderField 排序字段
	 * @param orderDirection 排序顺序
	 * @param paramField 参数key
	 * @param paramValue 参数value
	 * @return
	 * @author wuzq
	 * @date 2017-5-9下午1:25:43
	 * @retrun
	 */
	public static<T> PageResult<T> pageSet(Class clazz,Integer pageSize, Integer pageCurrent, String orderField, String orderDirection){
		/**
		 * 传入参数
		 */
		LogService.getInstance(clazz).debug("传入参数: pageSize = " + pageSize);
		LogService.getInstance(clazz).debug("传入参数: pageCurrent =" + pageCurrent);
		LogService.getInstance(clazz).debug("传入参数: orderField =" + orderField);
		LogService.getInstance(clazz).debug("传入参数: orderDirection = " + orderDirection);
//		LogService.getInstance(clazz).debug("传入参数: paramField =" + paramField);
//		LogService.getInstance(clazz).debug("传入参数: paramValue = " + paramValue);
		/**
		 * 参数初始化
		 */
		if (pageSize == null || pageSize == 0) {
			pageSize = 10;
		}
		if (pageCurrent == null || pageCurrent == 0) {
			pageCurrent = 1;
		}
		if (orderField == null || "".equals(orderField)) {
			orderField = "id";
		}
		if (orderDirection == null || "".equals(orderDirection)) {
			orderDirection = "asc";
		}
		
		LogService.getInstance(clazz).debug("实际: pageSize = " + pageSize);
		LogService.getInstance(clazz).debug("实际: pageCurrent =" + pageCurrent);
		LogService.getInstance(clazz).debug("实际: orderField =" + orderField);
		LogService.getInstance(clazz).debug("实际: orderDirection = " + orderDirection);
		
		/**
		 * 设置PageResult参数
		 */
 		PageResult<T> pageResult = new PageResult<T>();
		pageResult.setPageSize(pageSize);
		pageResult.setPageCurrent(pageCurrent);
		pageResult.setOrderField(orderField);
		pageResult.setOrderDirection(orderDirection);
//		if (paramValue != null && !"".equals(paramValue)) {
//			pageResult.getParam().put(paramField, paramValue);
//		}
		return pageResult;
	}
	
	/**
	 * <p>Title: multiFuzzyQuery</p>
	 * <p>Description:多条件组合查询初始化判断，排序使用</p>
	 * <p>Company: mesnac</p>
	 * @param list
	 * @return
	 * @author wuzq
	 * @date 2017-5-15下午9:26:47
	 * @retrun
	 */
	public static boolean multiFuzzyQuery(List<Boolean> list){
		boolean returnFlag = false;
		Integer sum = 0;
		for (Boolean flag : list) {
			if(!flag.booleanValue()){
				sum += 1;
			}
		}
		if(sum==list.size()){
			returnFlag = true;
		}else{
			returnFlag = false;
		}
		return returnFlag;
	}
}
